function [output]=merror2(funct,N,D,M) 
% merror2(funct,N,D,M) 
% 	Parameters:
% 		funct:	function used to produce a time series
% 		N:	size of time series
% 		D:	displacement
% 		M:	kernel size
% 
% 	Outputs:
% 		output	this function returns the value of the 500th term for the analytically shifted time
% 			series and the one for the 500th term of the time series shifted by interpolation
% 			(this was used in debugging)
% 
% 	Purpose of this code:  This code is used to plot the fractional error when a time series is shifted 
% 	by interpolation as opposed to shifting it by an analytic method.

% funct - function to be interpolated, N - number of data points, D -
% displacement, M - Size of Sinc Kernel
hold off;
%% Build Mesh.
x = 1:N;
%x01 = (x-1)/N;
x01 = x;
ts = funct(x01);%x01);

%% Shift using analytic methods.
sana = funct((x-D));
%plot(x01,sana,'r');
%hold on;

%% Shift using numeric methods.
%snum = FDtest(ts,N,D,M);
snum = FDtest(ts,D,M);
%plot(x01,snum,'b');
%hold on;

sanat = sana(500);
snumt = snum(500);
output = [sanat, snumt];
%% Plotting error discarding shift.
%SZ = (M-1)./2;
for j = 1:N
    %if (j < ((D+SZ)))
    if(j < D)
        err(j) = 0;
    else
        err(j) = abs(sana(j) - snum(j))./abs(sana(j));
    end
end

semilogy(x01,err);
%% Plot original time sequence
%plot (x01,ts,'g');

end
